package com.bu.utils

import android.Manifest
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v4.app.ActivityCompat
import android.view.View
import bu.utils.*
import kotlinx.android.synthetic.main.activity_main.*
import java.io.File

class MainActivity : AppCompatActivity() {
    private val permissions = arrayOf(Manifest.permission.READ_PHONE_STATE,Manifest.permission.READ_EXTERNAL_STORAGE)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        ActivityCompat.requestPermissions(this, permissions, 3333)
    }

    /* fun checkPermission() {
         if ((ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)) {
             ActivityCompat.requestPermissions(this, permissions, 3333)
         }
     }*/

    fun onBtnClick(v: View) {
        var text = "";
        when (v.id) {
            R.id.main_app -> {

                AppUtil.setWindowStatusBarColor(this, R.color.colorPrimary)
            }
            R.id.main_device -> {
                text = "设备信息: \n" +
                        DeviceUtil.getPhoneBrand() + " - " +
                        DeviceUtil.getPhoneModel() + "\n" +
                        DeviceUtil.getBuildLevel() + " - " +
                        DeviceUtil.getBuildVersion() + "\n" +

                        DeviceUtil.getPackageName(this) + "\n" +

                        DeviceUtil.getVersionCode(this) + "-" +
                        DeviceUtil.getVersionName(this) + "\n" +

                        DeviceUtil.isSDCardAvailable() + "\n" +

                        DeviceUtil.getDeviceId(this)
                main_result.text = text

            }
            R.id.main_screen -> {
                text = "ScreenWidth:" + ScreenUtil.getScreenWidth(this) + "\n" +
                        "ScreenHeight:" + ScreenUtil.getScreenHeight(this) + "\n" +
                        "StatusHeight:" + ScreenUtil.getStatusHeight(this) + "\n" +
                        "NavigationBarHeight:" + ScreenUtil.getNavigationBarHeight(this) + "\n" +
                        "hadNav:" + ScreenUtil.checkHasNavigationBar(this) + "\n" +
                        ""
                main_result.text = text


            }
            R.id.screen_shoot -> {
                if (image.visibility == View.VISIBLE) {
                    image.visibility = View.GONE
                } else {
                    image.visibility = View.VISIBLE
                    image.setImageBitmap(null)
                    image.setImageBitmap(ScreenUtil.snapShotWithoutStatusBar(this))
                }
            }
            R.id.main_network -> {
                text = "是否有网络连接:" + NetWorkUtil.isNetWorkEnable(this) + "\n" +
                        "网络是否为wifi:" + NetWorkUtil.isWiFiConnected(this) + "\n" +
                        "移动网络是否可用:" + NetWorkUtil.isMobileDataEnable(this) + "\n" +
                        "wifi是否可用:" + NetWorkUtil.isWifiDataEnable(this) + "\n" +
                        ""
                main_result.text = text
            }
            R.id.network_wifi_setting -> {
                NetWorkUtil.openWifiSetting(this)
            }
            R.id.network_mobile_setting -> {
                NetWorkUtil.openMobileSetting(this)
            }
            R.id.main_sp ->{
                startActivity(Intent(this,SPActivity::class.java))
            }
            R.id.main_md5 ->{
                main_result.text = MD5Util.md5(File("/storage/emulated/0/Download/HandShaker-offical.apk"))
            }
        }

    }


}
